package com.atguigu.realtime.util;

import com.atguigu.realtime.app.annotation.Nosink;
import com.atguigu.realtime.bean.ProductStats;
import com.atguigu.realtime.bean.VisitorStats;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class BeanUtil {
    // 返回这个类的所有的属性名
    public static <T>List<String> getFieldsNames(Class<T> tClass){
        ArrayList<String> list = new ArrayList<>();
        // TODO  getFields只能拿取pubic的 不能拿取private修饰的属性
        Field[] fields = tClass.getDeclaredFields();// 强制拿取所有的
        for (Field field : fields) {
            Nosink nosink = field.getAnnotation(Nosink.class);
            if (nosink == null) {
                String name = field.getName();
                list.add(name);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        List<String> list = getFieldsNames(ProductStats.class);
        for (String s : list) {
            System.out.println(s);
        }
    }
}
